package com.jaychen.eureka.client.util;

import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @Author Jay Chen
 * @Date 2020/10/26 19:13
 */
public class CommonUtil {

    /**
     * 生成MD5
     *
     * @param appName 服务名
     * @param port    端口号
     * @return InstanceId
     */
    public static String getInstanceId(String appName, String port) {
        return getHostAddress() + ":" + appName + ":" + port;
    }

    /**
     * 获取本机地址
     *
     * @return
     */
    public static String getHostAddress() {
        InetAddress addr = null;
        try {
            addr = InetAddress.getLocalHost();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        return addr.getHostAddress();
    }

}
